# -*- coding:utf-8 -*-
# @FileName  :edhcc_4_del_first.py
# @Time      :2021/1/12 13:40
# @Author    :Zhoujirong
# @Desc      : 删除第一个用户和角色

from common.log import Log
from biz.flow.user import UserRequest
from biz.cases.base_case import BaseCase
from common.utils import get_redis,get_mysql
from conf.settings import DB_TYPE
from biz.flow.role import RoleRequest

class TestCleanFirstUser(BaseCase):

    data_file_name = 'setup.yaml'

    @classmethod
    def setUpClass(cls):
        cls.redis = get_redis()
        cls.cookie = BaseCase().get_token_first()
        cls.cookie = BaseCase().get_token_admin()
        cls.db = get_mysql(DB_TYPE)

    #第一个用户
    def get_page_user(self):
        '''检索第一个用户'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_LIKE_userName = self.file_data.get('userName')
        search_LIKE_nickName = self.file_data.get('nickName')
        search_IN_orgId = self.file_data.get('orgId')
        search_IN_userType = self.file_data.get('userType')
        search_EQ_stopFlag = self.file_data.get('stopFlag')
        search_EQ_lockFlag = self.file_data.get('lockFlag')
        ret = UserRequest.get_page(curPage,
            maxSize,
            search_LIKE_userName,
            search_LIKE_nickName,
            search_IN_orgId,
            search_IN_userType,
            search_EQ_stopFlag,
            search_EQ_lockFlag,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0]

    def test_a_del_role1(self):
        '''删除在使用的角色'''
        ids = self.get_page_role()
        ret = RoleRequest.role_del(ids,self.cookie)
        Log.info(ret)
        self.assertEqual('00000003', ret.code)
        self.assertEqual('正在被用户使用的角色不能删除', ret.msg)

    def test_b_update_user(self):
        '''解绑test用户和角色'''
        data = self.get_page_user()
        address = data.address
        createNickname = data.createNickname
        createTime = data.createTime
        createUsername = data.createUsername
        deptId = data.deptId
        deptName = data.deptName
        desc1 = data.desc1
        desc2 = data.desc2
        desc3 = data.desc3
        desc4 = data.desc4
        desc5 = data.desc5
        desc6 = data.desc6
        ext1 = data.ext1
        ext10 = data.ext10
        ext11 = data.ext11
        ext12 = data.ext12
        ext13 = data.ext13
        ext14 = data.ext14
        ext15 = data.ext15
        ext16 = data.ext16
        ext17 = data.ext17
        ext18 = data.ext18
        ext19 = data.ext19
        ext2 = data.ext2
        ext20 = data.ext20
        ext21 = data.ext21
        ext22 = data.ext22
        ext23 = data.ext23
        ext24 = data.ext24
        ext25 = data.ext25
        ext26 = data.ext26
        ext27 = data.ext27
        ext28 = data.ext28
        ext29 = data.ext29
        ext3 = data.ext3
        ext30 = data.ext30
        ext4 = data.ext4
        ext5 = data.ext5
        ext6 = data.ext6
        ext7 = data.ext7
        ext8 = data.ext8
        ext9 = data.ext9
        id = data.id
        idCard = data.idCard
        ipbindflag = data.ipbindflag
        ipbindnum = data.ipbindnum
        lockFlag = data.lockFlag
        macbindflag = data.macbindflag
        macbindnum = data.macbindnum
        mark = data.mark
        mobile = data.mobile
        nickName = data.nickName
        orgId = data.orgId
        orgPhone = data.orgPhone
        password = data.password
        plainPassword = data.plainPassword
        postCode = data.postCode
        pwdUpdateTime = data.pwdUpdateTime
        resetFlag = data.resetFlag
        roleName = data.roleName
        salt = data.salt
        shortcutFlag = data.shortcutFlag
        stopFlag = data.stopFlag
        stopReason = data.stopReason
        stopTime = data.stopTime
        telephone = data.telephone
        updateNickname = data.updateNickname
        updateTime = data.updateTime
        updateUsername = data.updateUsername
        userEmail = data.userEmail
        userName = self.file_data.get('userName')
        userType = data.userType
        weiChat = data.weiChat
        orgTree = self.file_data.get('orgTree')
        roleIds = ''
        assignRoleIds = ''
        ret = UserRequest.user_update(assignRoleIds,address,
                                                    createNickname,
                                                    createTime,
                                                    createUsername,
                                                    deptId,
                                                    deptName,
                                                    desc1,
                                                    desc2,
                                                    desc3,
                                                    desc4,
                                                    desc5,
                                                    desc6,
                                                    ext1,
                                                    ext10,
                                                    ext11,
                                                    ext12,
                                                    ext13,
                                                    ext14,
                                                    ext15,
                                                    ext16,
                                                    ext17,
                                                    ext18,
                                                    ext19,
                                                    ext2,
                                                    ext20,
                                                    ext21,
                                                    ext22,
                                                    ext23,
                                                    ext24,
                                                    ext25,
                                                    ext26,
                                                    ext27,
                                                    ext28,
                                                    ext29,
                                                    ext3,
                                                    ext30,
                                                    ext4,
                                                    ext5,
                                                    ext6,
                                                    ext7,
                                                    ext8,
                                                    ext9,
                                                    id,
                                                    idCard,
                                                    ipbindflag,
                                                    ipbindnum,
                                                    lockFlag,
                                                    macbindflag,
                                                    macbindnum,
                                                    mark,
                                                    mobile,
                                                    nickName,
                                                    orgId,
                                                    orgPhone,
                                                    password,
                                                    plainPassword,
                                                    postCode,
                                                    pwdUpdateTime,
                                                    resetFlag,
                                                    roleName,
                                                    salt,
                                                    shortcutFlag,
                                                    stopFlag,
                                                    stopReason,
                                                    stopTime,
                                                    telephone,
                                                    updateNickname,
                                                    updateTime,
                                                    updateUsername,
                                                    userEmail,
                                                    userName,
                                                    userType,
                                                    weiChat,
                                                    orgTree,
                                                    roleIds,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertEqual('操作成功',ret.msg)

    def get_page_role(self):
        '''检索角色'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_LIKE_name = self.file_data.get('role_name')
        search_EQ_roleType = self.file_data.get('add_roleType')
        ret = RoleRequest.role_getpage(curPage,maxSize,search_LIKE_name,
                                       search_EQ_roleType,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0].id

    def test_c_del_role(self):
        '''删除初始角色'''
        ids = self.get_page_role()
        ret = RoleRequest.role_del(ids, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertEqual('操作成功', ret.msg)

    def test_d_del_user1(self):
        '''登陆过删除'''
        ids = self.get_page_user().id
        ret = UserRequest.del_user(ids, self.cookie)
        Log.info(ret)
        self.assertEqual('00000001', ret.code)
        self.assertEqual('登录过的用户不能删除', ret.msg)

    def test_e_del_user(self):
        '''删除第一个用户test'''
        sql = 'delete from SYS_USER_LOGIN_LOG'
        self.db.execute(sql)
        Log.info('登录信息表已清空')
        ids = self.get_page_user().id
        ret = UserRequest.del_user(ids, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertEqual('操作成功', ret.msg)



if __name__ == "__main__":
    pass